package com.cctc.rds.raft.sdk.client.rpc;

import com.cctc.rds.raft.core.node.NodeIpPort;
import com.cctc.rds.raft.core.rpc.RpcClientRouter;
import com.cctc.rds.raft.core.rpc.log.LogRpc;
import com.cctc.rds.raft.sdk.client.RaftClient;
import com.cctc.rds.raft.sdk.client.rpc.log.LogRpcRequestImpl;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public class LogRpcClientRouter implements RpcClientRouter<LogRpc> {
        private int nodeId;
        private RaftClient raftClient;

        @Override
    public LogRpc route(NodeIpPort ipPort) {
        if (ipPort.getNodeId() == this.nodeId)
            throw new RuntimeException("不允许向自己发送 RPC 请求！！！");
        return new LogRpcRequestImpl(raftClient.getNettyRpcClient(nodeId));
    }
}
